<template>
  <div class="box">
    <h1>A组件，{{ count }}</h1>
    <van-button type="primary" @click="handlePlus">数字+</van-button>
    <van-button type="info" @click="handleAdd">新增商品</van-button>
    <div v-for="(item, index) in goods" :key="index">
      名称:{{ item.name }} -- 价格:{{ item.price }}
    </div>
  </div>
</template>

<script>
export default {
  computed: {
    count() {
      return this.$store.state.count.num;
    },
    goods() {
      return this.$store.state.goodsModule.goods;
    },
  },
  methods: {
    handlePlus() {
      this.$store.commit("count/increment"); //触发mutations执行
    },
    handleAdd() {
      this.$store.commit("goodsModule/goodsAddMut", {
        name: "新商品",
        price: Math.round(Math.random() * 400 + 300),
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  height: 400px;
  border: 1px solid #333;
  font-size: 3rem;
}
</style>
